package threshold;

/**
 * @Author wujiaming
 * @Description TODO
 * @Date 2023-03-07 16:47
 * @Version 1.0
 */
public class SortedArrayToBst {


    /**
     * 根据一个有序数组构造一个平衡二叉树
     * 平衡二叉树的中序遍历是一个有序数组，每次取中间的那个数为根节点，这样递归的去下去即可
     * @param nums
     * @param low
     * @param high
     * @return
     */
    public TreeNode toBst(int[] nums,int low, int high){
        if(low>high){
            return null;
        }
        int mid = (low+high)/2;
        TreeNode root = new TreeNode(nums[mid]);
        root.left = toBst(nums,low,mid-1);
        root.right = toBst(nums,mid+1,high);
        return root;
    }
    public TreeNode sortedArrayToBST(int[] nums) {

        return toBst(nums, 0, nums.length - 1);
    }

    public static void main(String[] args) {
        int[] nums={-10,-3,0,5,9};


    }
}
